var upWindow = window.parent.frames["zwIframe"];

function fy_dialog_close() {
	window.parent.$(".mask").remove();
	window.parent.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger("click");
}

function getUpFields(name) {
	return upWindow.$("[validate*='name:\"" + name + "\"']");
}
function getUpFieldsByFieldval(name) {
	return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
}

function getUpAccountFieldValue(name) {
	var field = getUpFields(name).eq(0);
	return {
		displayValue : field.is("span") ? field.text() : field.val(),
		value : eval("(" + field.parent("span").attr("fieldVal") + ")").value
	};
}

function getSpanFieldValue(name) {
	var field = getUpFieldsByFieldval(name).eq(0);
	return eval("(" + field.attr("fieldVal") + ")").value;
}
// alert(window.parent.frames["zwIframe"].$("#field0002_txt").val());
function writeToForm() {
	try {
		var field = getUpFieldsByFieldval(getSpanFieldValue("companyField") + 1);
		var fieldVal = eval("(" + field.attr("fieldVal") + ")");
		var textValue = document.getElementById("companySelect").options[document
				.getElementById("companySelect").options.selectedIndex].text;

		field.find("#" + fieldVal.name).val(textValue);
		field.find("#" + fieldVal.name).trigger("blur");
	} catch (e) {
		var field = getUpFieldsByFieldval(getSpanFieldValue("companyField"));
		var fieldVal = eval("(" + field.attr("fieldVal") + ")");
		var textValue = document.getElementById("companySelect").options[document
				.getElementById("companySelect").options.selectedIndex].text;
		field.find("#" + fieldVal.name).val(textValue);
		field.find("#" + fieldVal.name).trigger("blur");
	}
	var syField = getUpFieldsByFieldval("送样评定表_公司");

	if (syField.length > 0) {
		syField.find("#" + eval("(" + syField.attr("fieldVal") + ")").name)
				.val(document.getElementById("companySelect").value);
	}
	fy_dialog_close();
}
function createOption(msg,key){
	var op = document.createElement("option");
	op.value = key;
	op.text = msg;
	return op;
}

window.onload = function() {
	if (getUpFields("送样评定表_公司").length > 0) {
		document.getElementById("companySelectTable").style.display = "";
		document.getElementById("companySelect").options.add(createOption(
				"福建省万达汽车玻璃工业有限公司", "0"));
		document.getElementById("companySelect").options.add(createOption(
				"福耀（福建）巴士玻璃有限公司", "1"));
		document.getElementById("companySelect").options.add(createOption(
				"福耀（福建）玻璃包边有限公司", "2"));
	} else if (getUpAccountFieldValue("单位选择器").value == "4886522247480361050") {
		document.getElementById("companySelectTable").style.display = "";
		document.getElementById("companySelect").options.add(createOption(
				"福建省万达汽车玻璃工业有限公司", "0"));
		document.getElementById("companySelect").options.add(createOption(
				"福耀玻璃工业集团股份有限公司", "1"));
	} else {
		fy_dialog_close();
	}
}